package com.feiyu.entity;

import com.feiyu.gen.BaseParam;
import com.feiyu.util.StringUtil;

import java.util.Objects;

/**
 * @author nanshouxiao@teacher.com.cn
 * @date 2018-08-27 11:00
 */
public class BaseColumnInfo {
    /**
     * 列名
     */
    private String columnName;
    /**
     * 列中文名
     */
    private String columnComment;
    /**
     * 列的java名称
     */
    private String columnJavaName;
    /**
     * 列的类型
     */
    private String javaType;
    /**
     * 如果为 auto_increment，则为自增
     */
    private String extra;
    /**
     * 如果为 PRI ，则为主键
     */
    private String columnKey;
    /**
     * 列的类型
     */
    private String dataType;

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
        this.columnJavaName = StringUtil.getHumName(columnName);
    }

    public String getColumnComment() {
        return columnComment;
    }

    public void setColumnComment(String columnComment) {
        this.columnComment = columnComment;
    }

    public String getColumnJavaName() {
        return columnJavaName;
    }

    public String getJavaType() {
        return javaType;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
        this.isAutoIncrement = Objects.equals("auto_increment", extra);
    }

    public String getColumnKey() {
        return columnKey;
    }

    public void setColumnKey(String columnKey) {
        this.columnKey = columnKey;
        this.isPrimaryKey = Objects.equals("PRI", columnKey);
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
        this.javaType = BaseParam.jdbcToJavaTypeMap.getOrDefault(dataType, "Object");
    }

    /**
     * 是否为自增
     */
    private boolean isAutoIncrement;
    /**
     * 是否为主键
     */
    private boolean isPrimaryKey;

    public boolean getIsAutoIncrement() {
        return isAutoIncrement;
    }

    public boolean getIsPrimaryKey() {
        return isPrimaryKey;
    }
}
